package com.project.servlet;

import com.project.Util.UtfUtil;
import com.project.bean.ManBean;
import com.project.service.IManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author lyl
 * description:根据选中的id显示相关信息
 */
@Controller
public class FindOneServlet extends HttpServlet {

    @Autowired
    private IManService iManService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UtfUtil.utfUtil(req, resp);
        PrintWriter pw = resp.getWriter();
        int manId = Integer.parseInt(req.getParameter("manId"));
        ManBean manBean = iManService.findOne(manId);
        String inputs = "<form action=" + "http://localhost:8088/update" + " method='post'>";
        inputs += "公民编号<input type='text' readonly='true' name=manId value=" + manId + "><br>";
        inputs += "姓名<input type='text' readonly='true' name='manName' value=" + manBean.getManName() + "><br>";
        inputs += "生日<input type='text' name='birthday' value=" + manBean.getBirthday() + ">";
        inputs += "<input type='submit' value='点击修改'>";
        inputs += "</form>";
        pw.println(inputs);
    }
}
